<?php

/**
 * sala actions.
 *
 * @package    blackDrums
 * @subpackage sala
 * @author     your name here
 */
class salaActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->Salas = SalaPeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->Sala = SalaPeer::retrieveByPk($request->getParameter('idsala'));
    $this->forward404Unless($this->Sala);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new SalaForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new SalaForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($Sala = SalaPeer::retrieveByPk($request->getParameter('idsala')), sprintf('Object Sala does not exist (%s).', $request->getParameter('idsala')));
    $this->form = new SalaForm($Sala);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($Sala = SalaPeer::retrieveByPk($request->getParameter('idsala')), sprintf('Object Sala does not exist (%s).', $request->getParameter('idsala')));
    $this->form = new SalaForm($Sala);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($Sala = SalaPeer::retrieveByPk($request->getParameter('idsala')), sprintf('Object Sala does not exist (%s).', $request->getParameter('idsala')));
    $Sala->delete();

    $this->redirect('sala/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $Sala = $form->save();

      $this->redirect('sala/edit?idsala='.$Sala->getIdsala());
    }
  }
}
